//package com.baizhi.cmfz.shiro;
//
//import com.baizhi.cmfz.dao.AdminDao;
//import com.baizhi.cmfz.entity.Admin;
//import org.apache.shiro.authc.*;
//import org.apache.shiro.realm.AuthenticatingRealm;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//
//public class AuthenRealm2 extends AuthenticatingRealm {
//	@Resource
//	private AdminDao adminDao;
//	@Override
//	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
////		1.获取token中的数据
//		UsernamePasswordToken token = (UsernamePasswordToken)authenticationToken;
//		String username = token.getUsername();
////		2.到数据库中查询数据
//		Admin admin = adminDao.selectAdminByNameAndPassword(username);
////		3.判断admin是不是空
//		if (admin != null) {
////			获取session对象
//			ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//			HttpServletRequest request = requestAttributes.getRequest();
//			HttpSession session = request.getSession();
//			session.setAttribute("admin",admin);
////			参数1：是账号（身份信息） 参数2：是凭证信息，参数3：是当前类的类名
//			return new SimpleAuthenticationInfo(admin.getAdminName(),admin.getAdminPassword(),this.getName());
//		}
//		return null;
//	}
//}
